package com.xcity.game.equip.suit4.impl;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.Combat;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.equip.suit4.BaseSuit4;
import com.xcity.game.equip.template.EquipSuitEffectTemplate;

/**
 * 卡地亚4件套<br/>
 * 暴击时有{50}%的几率对目标造成目标最大生命值{10}%的伤害
 * @author yang.li
 *
 */
public class Suit4Cartire extends BaseSuit4 {

	public Suit4Cartire(CombatUnit unit, EquipSuitEffectTemplate template) {
		super(unit, template);
	}

	@Override
	public void afterDamage0(ActionEffect effect) {
		if (unit.getId() != effect.ref().getUnitId()) {
			return;
		}
		if (effect.getResult() == ActionEffect.RESULT_CRIT
				&& !effect.getUnit().isDied()
				&& Combat.RND.nextInt(GameStaticConfig.percentBase) < template.getSuit4Param(0)) {
			Action newAct = new Action(unit);
			effect.ref().ref().add(newAct);
			ActionEffect eff = newAct.addTarget(effect.getUnit());
			int hpDelta = (int) (effect.getUnit().getMaxHp() * template.getSuit4Param(1) / GameStaticConfig.percentBase);
			int damageMax = (int) unit.getAttackPower();
			if (hpDelta > damageMax) {
				hpDelta = damageMax;
			}
			eff.effect(CombatAttributeType.HP, -hpDelta);
		}
	}


}
